import React, { PureComponent } from 'react';
import { connect } from 'react-redux';
import { withRouter } from 'react-router-dom';
import styles from  './style.module.scss';
class planCard extends PureComponent {
    render () {
        const {plan} = this.props;
        return (
            <div>
                <div className={styles['plan-item'] + ' ' +  ( parseInt(plan['status'])  === 0 ? 'not' : '') }>
                    <div className={styles['plan-wrap']}>
                        <div className={styles['plan-content']}>
                            <div className={styles['day']}>
                                <div className={styles['desc']}>day {  10 > plan['section_day'] ? '0' +  plan['section_day'] : plan['section_day']}</div>
                                <div className={styles['clock']}>
                                {
                                    (()=>{
                                        if (parseInt(plan['clock_state']) === 1) {
                                            return (<img src="https://mobuz-mp.cdn.bcebos.com/matter/complete_02@2x.png" alt=""/>)
                                        }
                                    })()
                                }
                                </div> 
                            </div>
                            <div className={styles['title']}>{plan['section_name']}</div>
                            <div className={styles['rate']}>
                                {/* 星星代码 */}
                                {this.starListHtml()}  
                                <div className={styles['score']}>{parseInt(plan.status) === 0 ? '---' : plan.all_score}</div>
                            </div> 
                        </div>
                        <div className={styles['plan-banner'] + ' ' + (plan['section_cover'] === '' ? styles['not_banner'] : '')}>
                            <img src={plan['section_cover']} alt=""/>
                        </div>
                    </div>
                    {
                        (()=>{
                            if (parseInt(plan.status) === 0) {
                                return (
                                    <img className={styles['not-unlock']}  src="https://mobuz-mp.cdn.bcebos.com/matter/willPlanTableNotUnlock.png" alt="" />
                                )
                            }
                        })()
                    }
                   
                </div>
            </div>
        )
    }
    // 星星代码
    starListHtml () {
        const {plan} = this.props;
        let arr = [0,1,2];
        return (
            <div className={styles['star']}>
               {
                   arr.map((i)=>{
                        return (<img key={i} src={parseInt(plan.all_start) >= i+1? 'https://mobuz-mp.cdn.bcebos.com/matter/star_fill@2x.png' :'https://mobuz-mp.cdn.bcebos.com/matter/star_empty@2x.png'} alt=""/>);
                   })
               }
            </div>
        )
    }
    // 跳转详情界面
    async gotoCourseCircumstance (item) {
        // 今天零点时间
        let currentDay = new Date(new Date(new Date().toLocaleDateString()).getTime()).getTime();
        // 点击的日历时间
        let itemDate = this.courseStartTime + ((item['section_day'] - 1 )*this.day_ms);;
        if (item.section_id) {
            if (item.status == 0) {
                alert("尚未解锁");
                return false;
            }
            // 预防重复点击
            if (!this.astrictClickFlag) {
                this.astrictClickFlag = true;
                setTimeout(async () => {
                    if (this.courseStartTime >= 1542643200000) {
                        // await statAwardsCase(this.student_id,this.batch_id)
                        //     .then(res => {
                        //         this.astrictClickFlag = false;
                        //         if (res.status === 200) {
                        //           //   wx.navigateTo({
                        //           //       url: '../courseCircumstance/main?section_id='+item.section_id+'&batch_id='+this.batch_id
                        //           //   })
                        //           this.gotoPage(item)
                        //         } else if (res.status === 202) {
                        //             // 提醒只有一次
                        //             if (!this.remindFlag) {
                        //                 // wx.showModal({
                        //                 //     content: '课程结束后，5天内拥有课程回看权限',
                        //                 //     showCancel: false,
                        //                 //     success: ()=> {
                        //                 //       //   wx.navigateTo({
                        //                 //       //       url: '../courseCircumstance/main?section_id='+item.section_id+'&batch_id='+this.batch_id
                        //                 //       //   })
                        //                 //       this.gotoPage(item)
                        //                 //     }
                        //                 // })
                        //                 this.remindFlag = true;
                        //             } else {
                        //               //   wx.navigateTo({
                        //               //       url: '../courseCircumstance/main?section_id='+item.section_id+'&batch_id='+this.batch_id
                        //               //   })
                        //               this.gotoPage(item)
                        //             }
  
                        //         } else {
                        //             // showMessager(res.msg);
                        //         }
  
                        //     })
                        //     .actch( err => {
                        //         // showMessager("网络拥堵，请稍后再试");
                        //     })
                    } else {
                          this.astrictClickFlag = false;
                      //   wx.navigateTo({
                      //       url: '../courseCircumstance/main?section_id='+item.section_id+'&batch_id='+this.batch_id
                      //   })
                        //   this.gotoPage(item)
                    }
  
                }, 50);
            }
        }
  
      }
}
export default connect(null,null)(withRouter(planCard));
